import { Scene } from "../../../../../Core/Module/Entity/Scene";
import { EventSystem } from "../../../../../Core/Module/EventSystem/EventSystem";
import { UnitInfo } from "../../../../Model/Generate/Share/Message/OuterMessage_C_10001";
import { EventType } from "../../../../Model/Share/Demo/EventType";
import { ObjectWait } from "../../../../Model/Share/Module/ObjectWait/ObjectWait";
import { Unit } from "../../../../Model/Share/Module/Unit/Unit";
import { UnitComponent } from "../../../../Model/Share/Module/Unit/UnitComponent";

export class UnitFactory {

    public static Create(currentScene: Scene, unitInfo: UnitInfo): Unit {
        let unitComponent = currentScene.GetComponent<UnitComponent>(UnitComponent);
        let unit = unitComponent.AddChildWithId<Unit, number>(Unit, unitInfo.UnitId, unitInfo.ConfigId);
        unitComponent.Add(unit);

        unit.AddComponent<ObjectWait>(ObjectWait);

        let afterUnitCreate = new EventType.AfterUnitCreate();
        afterUnitCreate.Unit = unit;
        EventSystem.Instance.Publish(currentScene, afterUnitCreate);
        return unit;
    }

}